﻿@{
    ViewBag.Title = "碳化硅信息列表";
}
@section SideNav{@Html.Partial("SideNavPartialView")}

<ol class="breadcrumb">
    <li><span class="glyphicon glyphicon-home"></span>  @Html.ActionLink("首页", "Index", "Home")</li>
    <li class="active">@Html.ActionLink("物料管理", "Index", "Breaked")</li>
    <li class="active">@Html.ActionLink("碳化硅信息", "Index", "SiliconCarbide")</li>
</ol>

<div id="toolbar" class="btn-group" role="group">
    <button id="btn_add" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span>添加</button>
</div>

<table id="siliconcarbidegrid"></table>
@section scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            var $table = $('#siliconcarbidegrid');
            $table.bootstrapTable({
                toolbar: "#toolbar",
                showRefresh: true,
                showColumns: true,
                pageNumber: 1,
                pageSize: 10,
                pagination: true,
                sidePagination: "server",
                pageList: "[5, 10, 20, 50, 100]",
                method: "post",
                url: "@Url.Action("PageList")",
                queryParams: queryParams,
                queryParamsType: "limit", //参数格式,发送标准的RESTFul类型的参数请求
                columns: [
                    { title: "ID", field: "SiliconCarbideID" },
                    { title: "名称", field: "Name" },
                    { title: "是否禁用", field: "IsDisabled", formatter: function (value) { if (value > 0) return "<font color='#00CC33'>否</font>"; else return "<font color='#FF0000'>是</font>"; } },
                    { title: "创建时间", field: "Created_at", formatter: function (value) { return moment(value).format("YYYY-MM-DD HH:mm:ss") } },
                    { title: "更新时间", field: "Updated_at", formatter: function (value) { return moment(value).format("YYYY-MM-DD HH:mm:ss") } },
                    {
                        title: "操作", field: "SiliconCarbideID", formatter: function (value) {
                            return "<a class='btn btn-sm btn-primary' href ='#' data-method='Modify' data-value=" + value + ">编辑</a> <a class='btn btn-sm btn-danger' data-method='Delete' data-value='" + value + "'>删除</a>"

                        }
                    }
                ],

                onAll: function (name, args) {
                    if ((name == "load-success.bs.table") || (name == "column-switch.bs.table")) {
                        //删除按钮
                        $("a[data-method='Delete']").click(function () {
                            var id = $(this).attr("data-value");
                            BootstrapDialog.confirm("确定要删除该项", function (result) {
                                if (result) {
                                    $.post("@Url.Action("Delete")", { siliconCarbideid: id }, function (data) {
                                        if (data.Code == 1) {
                                            BootstrapDialog.show({
                                                message: "删除成功",
                                                buttons: [{
                                                    icon: "glyphicon glyphicon-ok",
                                                    label: "确定",
                                                    action: function (dialogItself) {
                                                        $table.bootstrapTable("refresh");
                                                        dialogItself.close();
                                                    }
                                                }]
                                            });
                                        }
                                        else BootstrapDialog.alert(data.Message);
                                    }, "json");
                                }
                            });
                        });
                        //删除结束

                        //修改
                        $("a[data-method='Modify']").click(function () {
                            var id = $(this).attr("data-value");
                            var modifyDialog = new BootstrapDialog({
                                title: "<span class='glyphicon glyphicon-user'></span>修改",
                                message: function (dialog) {
                                    var $message = $('<div></div>');
                                    var pageToLoad = dialog.getData('pageToLoad');
                                    $message.load(pageToLoad);

                                    return $message;
                                },
                                data: {
                                    'pageToLoad': '@Url.Action("Modify")/' + id
                                },
                                buttons: [{
                                    icon: "glyphicon glyphicon-plus",
                                    label: "保存",
                                    action: function (dialogItself) {
                                        $.post($("form").attr("action"), $("form").serializeArray(), function (data) {
                                            if (data.Code == 1) {
                                                BootstrapDialog.show({
                                                    message: data.Message,
                                                    buttons: [{
                                                        icon: "glyphicon glyphicon-ok",
                                                        label: "确定",
                                                        action: function (dialogItself) {
                                                            $table.bootstrapTable("refresh");
                                                            dialogItself.close();
                                                            modifyDialog.close();
                                                        }
                                                    }]

                                                });
                                            }
                                            else BootstrapDialog.alert(data.Message);
                                        }, "json");
                                        $("form").validate();
                                    }
                                }, {
                                    icon: "glyphicon glyphicon-remove",
                                    label: "关闭",
                                    action: function (dialogItself) {
                                        dialogItself.close();
                                    }
                                }]
                            });
                            modifyDialog.open();
                        });
                        //修改结束
                    }
                }
            });

            //添加
            $("#btn_add").click(function () {
                var addDialog = new BootstrapDialog({
                    title: "<span class='glyphicon glyphicon-plus'></span>添加",
                    message: function (dialog) {
                        var $message = $('<div></div>');
                        var pageToLoad = dialog.getData('pageToLoad');
                        $message.load(pageToLoad);

                        return $message;
                    },
                    data: {
                        'pageToLoad': '@Url.Action("Add")'
                    },
                    buttons: [{
                        icon: "glyphicon glyphicon-plus",
                        label: "添加",
                        action: function (dialogItself) {
                            if ($("form").valid()) {
                                $.post($("form").attr("action"), $("form").serializeArray(), function (data) {
                                    if (data.Code == 1) {
                                        BootstrapDialog.show({
                                            message: data.Message,
                                            buttons: [{
                                                icon: "glyphicon glyphicon-ok",
                                                label: "确定",
                                                action: function (dialogItself) {
                                                    $table.bootstrapTable("refresh");
                                                    dialogItself.close();
                                                    addDialog.close();
                                                }
                                            }]

                                        });
                                    }
                                    else BootstrapDialog.alert(data.Message);
                                }, "json");
                            }
                        }
                    }, {
                        icon: "glyphicon glyphicon-remove",
                        label: "关闭",
                        action: function (dialogItself) {
                            dialogItself.close();
                        }
                    }]
                });
                addDialog.open();
            });
            //添加结束

        })
    </script>

    <script type="text/javascript">
        function queryParams(params) {
            var temp = {
                pageNumber: params.offset,
                pageSize: params.limit
            };
            return temp;
        }
    </script>
}

